/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import dao.UsuarioDao;
import java.io.Serializable;
import java.sql.SQLException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import model.Usuario;
//import model.Login;

/**
 *
 * @author Elizangela
 */
@ManagedBean(name = "loginBean")
@SessionScoped
public class LoginBean implements Serializable {
    private Usuario login = new Usuario();
    
    public Usuario getLogin() {
        return login;
    }

    public String login() throws SQLException {        
        UsuarioDao usuarioDao= new UsuarioDao();
        boolean validarLogin = usuarioDao.login(login);
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("userlogged", validarLogin);
        if (validarLogin) {
            return "teste";
        } else {
            return "falha";
        }
        
    }

    public String sair() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        session.removeAttribute("userlogged");
        return "index";
    }
}
